Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update action filter execution process to run using the continuation style #44

Merged
merged 5 commits into from
Aug 15, 2019

Conversation

alistairjevans
Copy link
Member

@alistairjevans alistairjevans commented Jul 29, 2019

Fixes #34

This change removes the ActionFilterWrapper and replaces it with the ContinuationActionFilterWrapper, which implements IActionFilter rather than deriving from ActionFilterAttribute.

The logic in this new wrapper uses the continuation style to call each nested filter.

There is a new IAutofacContinuationActionFilter that allows users to directly implement a filter that uses continuations. The old IAutofacActionFilter is still supported, through the registration of an adapter that wraps the old-style filter in a AutofacActionFilterAdapter that replicates the behaviour of ActionFilterAttribute.

Regardless of the type of filter used, the async context is correctly maintained, so you can set the TransactionScope, for example, in the OnActionExecutingAsync of a normal filter and it will be maintained in the WebAPI action.

In the new continuation-style filter you can wrap the 'next' filter in a using block with a transaction scope and everything works as you would hope.

New tests have been added that explicitly validate that TransactionScope is maintained in all the right places for both filter types.

Note: I have directly copied the code from the ASP.NET source that invokes the OnActionExecutedAsync method, because I consider it to be the reference source of how to do it (and I've noted as such in the comments). Is this ok from a license/re-use perspective?

As far as I can tell this is not a breaking change of API or behaviour (thanks almost entirely to Autofac adapters).

…uation flow

The action filter wrapper has been replaced, and a new autofac filter interface defined with a registered adapter around the old style.
@tillig
Copy link
Member

tillig commented Aug 15, 2019

It looks like the ASP.NET web stack is licensed under Apache 2.0. Reading through that license, I gather this is the relevant bit:

  1. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
    a. You must give any other recipients of the Work or Derivative Works a copy of this License; and
    b. You must cause any modified files to carry prominent notices stating that You changed the files; and
    c. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
    d. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

I read that as:

  • For every file that has some copy/paste code, add a note at the top/in the header that some of the code here is from the Microsoft ASP.NET web stack, licensed under Apache 2.0.
  • Update the LICENSE in the root of the Autofac.WebApi repo to include license info for the ASP.NET web stack.

I mean, ideally we wouldn't have copy/paste code because of the licensing issues there, but it happens.

So... in files affected, something like:

// This software is part of the Autofac IoC container
// Copyright (c) 2013 Autofac Contributors
// https://autofac.org
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Portions of this file come from the Microsoft ASP.NET web stack, licensed
// under the Apache 2.0 license. You may obtain a copy of the license at
// http://www.apache.org/licenses/LICENSE-2.0

In the main LICENSE we'd add something like:

This software includes code from the open source Microsoft ASP.NET web stack,
licensed under the Apache 2.0 license. You may obtain a copy of the license at
http://www.apache.org/licenses/LICENSE-2.0

Does that sound about right, @alexmg / @nblumhardt ?

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really, really awesome. I think if you can add the licensing bit, we can go for it. Thank you for all the hard work here, and I'm sorry for being a bit out-of-pocket lately.

@alistairjevans
Copy link
Member Author

Thanks @tillig, I've updated the AutofacActionFilterAdapter with the file comment and updated the LICENSE file.
I really appreciate you making the time to progress this.

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@tillig tillig merged commit d4506ad into autofac:develop Aug 15, 2019
@alistairjevans
Copy link
Member Author

Also, now you're ok with the approach, I'll put documentation updates together on the docs repo for these changes.

@tillig
Copy link
Member

tillig commented Aug 15, 2019

I gather this is a 4.3.0 kind of release since it's backwards compatible but a new feature. Does that sound right to you (current release is 4.2.1)?

If so, let me know when you're ready to release and I can help with that.

@alistairjevans
Copy link
Member Author

Yeah, it's a 4.3.0; I already updated the appveyor file in a previous PR (for making the registration support more powerful).

I'm happy to release, unless you want to wait for the documentation changes?

@tillig
Copy link
Member

tillig commented Aug 15, 2019

Nope, I'm livin' on the edge today. Let's release this bad boy! :)

@alistairjevans
Copy link
Member Author

Sweet; is it mostly just a push from myget to nuget? Then create the release entry in the repo?

@tillig
Copy link
Member

tillig commented Aug 15, 2019

  • Merge from develop to master
  • Tag with v4.3.0
  • Push all that to GitHub
  • Let AppVeyor finish building - it'll build a 4.3.0 release in MyGet from master
  • Push from MyGet to NuGet
  • Create the release here, do the release notes, download the package from NuGet and attach to the release.

We have a section on this in the Owner's Guide, too.

@tillig
Copy link
Member

tillig commented Aug 15, 2019

Perfect, thanks! I'm drafting up the release now.

@tillig
Copy link
Member

tillig commented Aug 15, 2019

Released!

@alistairjevans
Copy link
Member Author

Awesome, thanks Travis. I'll put the documentation updates together soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad async/await implementation causing loss of execution context.
2 participants